<!DOCTYPE HTML>
<html>
<head>
    <#include "../common/_meta.html">
    <title>修改属性 ID:${resource.id}</title>
</head>
<body>
<article class="cl pd-20">
    <form class="form form-horizontal" name="form-edit-attribute" id="form-edit-attribute">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">集群：</label>
            <div class="formControls col-xs-8 col-sm-9">${resource.cluster!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">IP:端口：</label>
            <div class="formControls col-xs-8 col-sm-9">${resource.ip!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">属性：</label>
            <div class="formControls col-xs-8 col-sm-9">${resource.attribute!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">当前值：</label>
            <div class="formControls col-xs-8 col-sm-9">${resource.attributeValue!''}</div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>修改为：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" placeholder="不修改请留空" name="newattribute" id="newattribute">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存并推送&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<#include "../common/_footer.html">

<script type="text/javascript">
    $(function(){
        $("#form-edit-attribute").validate({
            rules:{
                newattribute:{
                    required:true
                },
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(){
                invoke();
            }
        });
    });

    function invoke() {
        var resourceId = ${resource.id};
        var attribute = "${resource.attribute!''}";
        var newAttribute = $("#newattribute").val();
        var cluster = "${resource.cluster!''}";
        var instance = "${resource.ip!''}";
        var index = layer.load(2);
        var currentValue = "${resource.attributeValue!''}";
        $.ajax({
            type: "POST",
            url: "${base}/resource_manage/push_attribute",
            data: {"resourceId": resourceId,
                "pushValue": newAttribute,
                "attribute": attribute,
                "cluster": cluster,
                "currentValue": currentValue,
                "instance": instance},
            dataType: "json",
            success: function (result) {
                layer.close(index);
                if(result.code === 0) {
                    layer.msg("推送成功", {icon:6,time:2000}, function () {layer_close();});
                } else {
                    layer.alert("推送失败", {icon:5,time:2000}, function () {layer_close();});
                }
            },
            error: function (result) {
                layer.close(index);
                layer.msg("内部错误", {icon:5,time:2000}, function () {layer_close();});
            }
        });
    }
</script>
</body>
</html>